#include "PlayState.h"



PlayState::PlayState()
{
}
PlayState::~PlayState(void)
{
}

 void PlayState::Load()
{
	map.Load("level01.txt", "texturepack01.txt");
	character.SetPosition(SVector2(512, 386));
	character.Load();
}
 void PlayState::Unload()
{
		map.Unload();
	character.Unload();
}
 NextState PlayState::Update(float deltaTime)
{
	character.Update(deltaTime, map);

	NextState nextState = None;
	if(Input_IsKeyDown(Keys::ESCAPE))
	{
		nextState = Frontend;
	}
	return nextState;
}
void PlayState::Render()
{
	const int kWinWidth = IniFile_GetInt("WinWidth", 800);  // ini files
	const int kWinHeight = IniFile_GetInt("WinHeight", 600);
	SVector2 viewTarget = character.Getposition();
	SVector2 viewOffset;
	viewOffset.x = (viewTarget.x - (kWinWidth * 0.5f)); 
	viewOffset.y = (viewTarget.y - (kWinHeight * 0.5f)); 
	SVector2 limit;
	limit.x = (float)map.GetWidth() - kWinWidth;
	limit.y = (float)map.GetHeight() - kWinHeight;

	viewOffset.x = Clamp(viewOffset.x, 0.0f, limit.x);
	viewOffset.y = Clamp(viewOffset.y, 0.0f, limit.y);
	map.Render(viewOffset);
	character.Render(viewOffset);
}